﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Data.SQLite;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 数据库
{
    public partial class Form1 : Form
    {
        ArrayList Chinese = new ArrayList();
        ArrayList English = new ArrayList();
        int pos = 0;
        int length;
        public Form1()
        {
            try
            {
                SQLiteConnection conn = null;

                string dbPath = "Data Source =" + Environment.CurrentDirectory + "/testDB.db";
                conn = new SQLiteConnection(dbPath);//创建数据库实例，指定文件位置  
                conn.Open();//打开数据库，若文件不存在会自动创建  

                string sql = "select * from words";
                SQLiteCommand cmdQ = new SQLiteCommand(sql, conn);

                SQLiteDataReader reader = cmdQ.ExecuteReader();

                while (reader.Read())
                {
                    Chinese.Add((string)reader["Chinese"]);
                    English.Add((string)reader["English"]);
                }
                conn.Close();
                length = Chinese.Count;
             
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }

            InitializeComponent();

            label4.Text = Chinese[pos].ToString();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == English[pos].ToString())
            {
                label5.Text = "true";
            }
            else
            {
                label5.Text = "false";
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            pos=(pos+1)%length;
            label4.Text = Chinese[pos].ToString();
            label5.Text = "点确认";
        }
    }
}
